package Thread.New.线程安全;


public class RunableImpl implements Runnable{

    private static int num = 100;
    //创建一个同步代码块，注意要在run方法外面
    @Override
    public void run() {
        while(true)
        {
            payTikcet();
        }

    }
    //这是建立的同步方法
    public static synchronized void payTikcet()
    {
        if (num > 0) {
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "-->" + num);
            num--;
            //用于卖票
        }
    }
}
